import React from "react";
import { useSelector, useDispatch } from "react-redux";

import { pushAction } from "./store/actionCreator";

const Child = () => {
  const count = useSelector((state) => state.count);
  const list = useSelector((state) => state.list);
  const dispatch = useDispatch();

  const fn = (name) => {
    dispatch(pushAction(name));
  };

  return (
    <div>
      child子组件 - {count} -{" "}
      <button onClick={() => dispatch({ type: "add" })}>btn2</button>
      <ul>
        {list.map((item, index) => (
          <li key={index}>{item}</li>
        ))}
      </ul>
      <button onClick={() => fn("wangwu")}>btn</button>
      <button onClick={() => fn("zhaoliu")}>btn</button>
    </div>
  );
};

export default Child;
